package demo1;

public class Computer {
    public void open(){
        System.out.println("开机");
    }
    public void close(){
        System.out.println("关机");
    }
    public void useDevice(IUSB usb){//使用向上转型传了一个类为IUSB的对象参数
        usb.openDevice();//将会调用相应参数的重写方法
        if (usb instanceof Mouse){//判断usb是否为Mouse的实例
            Mouse mouse = (Mouse)usb;
            mouse.click();
        }else if (usb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard)usb;
            keyBoard.inPut();
        }
        usb.closeDevice();
    }
}
